﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.Utility;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite
{
    public partial class News : WebSiteBaseicPage
    {

        private readonly NewsBLL _nbll = new NewsBLL();

        private readonly NewTypeBLL _ntbll = new NewTypeBLL();

        public string Id;

        protected List<NewsInfo> NewsList = new List<NewsInfo>();

        protected List<NewTypeInfo> NewTypeList = new List<NewTypeInfo>();

        protected void Page_Load(object sender, EventArgs e)
        {
            Id = Request.Params["id"];
            InitializationData();
            if (string.IsNullOrEmpty(Id))
            {
                LoadData(null, null);
            }
            else
            {
                if (RequestCheck.CheckKeyWord(Id))
                {
                    Response.Redirect("News.aspx");
                }
                else
                {
                    LoadData(null, null);
                }
            }
        }

        public void LoadData(object sender, EventArgs e)
        {
            Pagination1.PageIndex = sender != null ? Convert.ToInt32(((LinkButton)sender).CommandArgument) : 1;
            int recordcount = _nbll.GetTotal(Id);
            Pagination1.PageSize = 5;
            NewsList = _nbll.GetNewsList(Id, Pagination1.PageIndex, Pagination1.PageSize);
            Pagination1.RecordCount = recordcount;
        }

        private void InitializationData()
        {
            NewTypeList = _ntbll.GetNewTypeAndNewsCountList();
        }
    }
}